<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="sun.net.ftp.FtpClient"%>
<%@ page import="sun.net.TelnetInputStream"%>
<%@ page import= "com.asiainfo.common.Configure"%>
<%@ page import= "com.asiainfo.exchangeplatform.bean.*"%>
<%@ page import= "com.asiainfo.exchangeplatform.service.*"%>
<%@ page import="com.asiainfo.common.Pinyin"%>
<%@include file="/include.jsp"%>
<%
        String strCityName=Pinyin.getPinYin(m_strLoginCityName);
	String strFileName = request.getParameter("fileName") == null?"":request.getParameter("fileName");
	response.setContentType("application/x-msdownload");
	response.setHeader("Content-disposition","attachment;filename=\"" + strFileName + "\"");

	BufferedOutputStream  bos  =  null;
	try  {

		bos  =  new  BufferedOutputStream(response.getOutputStream());
                _jspxFactory = null;
		byte[]  buff  =  new  byte[2048];
		int  bytesRead;

		//ftp start
		String ftpHostIp = Configure.getInstance().getProperty("EXCHANGEPLATFORM_FTP_IP");
		int ftpHostPort = Integer.parseInt(Configure.getInstance().getProperty("EXCHANGEPLATFORM_FTP_PORT"));
		String ftpHostUser = Configure.getInstance().getProperty("EXCHANGEPLATFORM_FTP_USER");
		String ftpHostPwd = Configure.getInstance().getProperty("EXCHANGEPLATFORM_FTP_PWD");
		String ftpHostDir = Configure.getInstance().getProperty("CITYREPORT_FTP_DIR")+"exportLog"+"/";

		FtpClient ftpClient = new FtpClient();
      	        ftpClient.openServer(ftpHostIp, ftpHostPort);
		ftpClient.login(ftpHostUser, ftpHostPwd);
		ftpClient.binary();
		TelnetInputStream tis = ftpClient.get(ftpHostDir + strFileName);
                System.out.println(ftpHostIp+" "+ftpHostUser+" "+ftpHostPwd+" "+ftpHostDir+" "+strFileName);
		while(-1  !=  (bytesRead  =  tis.read(buff,  0,  buff.length)))
                {
			bos.write(buff,0,bytesRead);
		}
		//ftp end

		bos.flush();

	}  catch(IOException  e)  {

	}  finally  {

		if  (bos  !=  null)
			bos.close();
	}
%>
